/**
 *
 * Created by shenzaifang on 2019-04-28
 */
import React, {Component} from 'react';
import {base} from 'nc-lightapp-front';
import AddRefer from 'src/hrpub/common/components/hr-refer/ReferLoader';

const {
    NCInput,
    NCButton,
    NCSelect,
    NCDatePicker
} = base;
const {NCOption} = NCSelect;
const RangePicker = NCDatePicker.NCRangePicker;

function OrgRefer(props) {
    let {val, onChange, language} = props;
    return <div className={'refer-item'}>
        <span className={'refer-label'}>{language["gx6008-000134"]}</span>
        <AddRefer
            {...{
                refcode: '/uapbd/refer/org/AdminOrgDefaultTreeRef/index',
                value: val,
                isMultiSelectedEnabled: true,
                // style: {width: '160px'},
                onChange: (value)=>{
                    onChange(value)
                },
                queryCondition: () => {
                    return {
                        "TreeRefActionExt": "nccloud.web.hr.sqlbuilder.HRPrimaryOrgSQLBuilder",
                        controlType: 2,
                        isShowDisable: false
                    }
                }
            }}
        />
    </div>
}

/**
 * 人员类别
 * @param props
 * @returns {*}
 */
function PsnclRefer(props) {
    const {val, onChange, language} = props;
    return <div className={'refer-item'}>
        <span className={'refer-label'}>{language["gx6008-000135"]}</span>
        <AddRefer
            {...{
                refcode: 'uapbd/refer/psninfo/PsnclTreeRef/index',
                value: val,
                isMultiSelectedEnabled: true,
                onChange: onChange,
                // style: {width: '160px'},
            }}
        />
    </div>
}

/**
 * 职等
 * @param props
 * @returns {*}
 */
function JobRankRefer(props) {
    const {val, onChange, language} = props;
    return <div className={'refer-item'}>
        <span className={'refer-label'}>{language["gx6008-000163"]}</span>
        <AddRefer
            {...{
                refcode: 'hrjf/refer/jfref/JobRankGridRef/index',
                value: val,
                onChange: (val) => {
                    onChange(val)
                },
                // style: {width: '160px'},
            }}
        />
    </div>
}

/**
 * 学历
 * @param props
 * @returns {*}
 */
function DefdocRefer(props) {
    const {val, onChange, language} = props;
    return <div className={'refer-item'}>
        <span className={'refer-label'}>{language["gx6008-000164"]}</span>
        <AddRefer
            {...{
                refcode: 'uapbd/refer/userdef/DefdocTreeRef/index',
                value: val,
                onChange: (val) => {
                    onChange(val)
                },
                // style: {width: '160px'},
                queryCondition: () => {
                    return {
                        "pk_defdoclist": "1001Z71000000000GP4V"
                    }
                }
            }}
        />
    </div>
}

/**
 * 合同主体
 * @param props
 * @returns {*}
 */
function ContractRefer(props) {
    const {val, onChange, language} = props;
    let label = language["gx6008-000165"];
    return <div className={'refer-item'}>
        <span className={'refer-label'}>{label}</span>
        <AddRefer
            {...{
                refcode: '/uapbd/refer/org/AdminOrgDefaultTreeRef/index',
                value: val,
                // style: {width: '160px'},
                onChange: (val) => {
                    onChange(val)
                },
                // placeholder: label.slice(0,-1),
                queryCondition: () => {
                    return {
                        "TreeRefActionExt": "nccloud.web.hr.sqlbuilder.HRPrimaryOrgSQLBuilder",
                        controlType: 2,
                        isShowDisable: false
                    }
                }
            }}
        />
    </div>
}

/**
 * 入职类型/变动类型/离职类型
 * @param val
 * @param onChange
 * @param language
 * @param queryCondition
 * @param label
 * @returns {*}
 */
function typeRefer(val, onChange, language, queryCondition, label) {
    return <div className={'refer-item'}>
        <span className={'refer-label'}>{language[label]}</span>
        <AddRefer
            {...{
                refcode: 'hrhi/refer/hiref/TrnsTypeGridRef/index',
                value: val,
                onChange: (val) => {
                    onChange(val)
                },
                // style: {width: '160px'},
                queryCondition: () => {
                    return queryCondition
                }
            }}
        />
    </div>
}

/**
 * 入职类型
 * @param props
 * @returns {*}
 */
function EntryTypeRefer(props) {
    const {val, onChange, language} = props;
    return typeRefer(val, onChange, language, {trnsEvent: 1}, 'gx6008-000168')
}

/**
 * 变动类型
 * @param props
 * @returns {*}
 */
function ChangeTypeRefer(props) {
    const {val, onChange, language} = props;
    return typeRefer(val, onChange, language, {trnsEvent: 3}, 'gx6008-000169')
}

/**
 * 离职类型
 * @param props
 * @returns {*}
 */
function DimiTypeRefer(props) {
    const {val, onChange, language} = props;
    return typeRefer(val, onChange, language, {trnsEvent: 4}, 'gx6008-000170')
}

/**
 * 年龄
 * @param props
 * @returns {*}
 */
function AgeRefer(props) {
    const {val, onChange, language} = props;
    const ageList = [
        {
            key: null,
            label: " ",//25岁以下
        },
        {
            key: 1,
            label: "gx6008-000175",//25岁以下
        },
        {
            key: 2,
            label: "gx6008-000176",//25-30岁
        },
        {
            key: 3,
            label: "gx6008-000177",//31-45岁
        },
        {
            key: 4,
            label: "gx6008-000178",//46-55岁
        },
        {
            key: 5,
            label: "gx6008-000179",//56岁以上
        }
    ];
    return <div className={'refer-item'}>
        <span className={'refer-label'}>{language["gx6008-000171"]}</span>
        <NCSelect
            multiple={false}
            showClear={false}
            style={{
                // "width": '160px'
            }}
            placeholder={language["gx6008-000171"]}
            onChange={onChange}
            value={val}
        >
            {ageList.map((item) => {
                return (
                    <NCOption
                        key={item.key}
                        value={item.key}
                    >
                        {language[item.label]}
                    </NCOption>
                );
            })}
        </NCSelect>
    </div>
}

/**
 * 员工编码
 * @param props
 * @returns {*}
 */
function StaffCodeRefer(props) {
    const {val, onChange, language} = props;
    return <div className={'refer-item'}>
        <span className={'refer-label'}>{language["gx6008-000172"]}</span>
        <NCInput type="text" value={val} onChange={onChange}/>
    </div>
}

/**
 * 起止日期
 * @param props {val, onChange, language}
 * @returns {*}
 */
function RangeDateRefer(props) {
    const {val, onChange, language, param = {}} = props;
    return <div className={'refer-item'}>
        <span className={'refer-label'}>{language["gx6008-000173"]}</span>
        <RangePicker
            value={val}
            onChange={onChange}
            placeholder={language['gx6008-000174']}
            className={'range-picker'}
            {...param}
        />
    </div>
}

/**
 * emptyRefer
 * @returns {*}
 */
function EmptyRefer() {
    return <div className={'refer-item'}>
        <span className={'refer-label'}>

        </span>
        <div

        />
    </div>
}

/**
 * formBtn
 * @returns {*}
 */
function FormBtn(props) {
    const {action, staffCom} = props;
    return <div className={'form-btn'}>
        <NCButton onClick={action.thisAct.search} colors={"primary"}>{staffCom.language["gx6008-000159"]}</NCButton>
        <NCButton onClick={action.thisAct.clear}>{staffCom.language["gx6008-000162"]}</NCButton>
    </div>
}

export {
    OrgRefer,
    PsnclRefer,
    JobRankRefer,
    DefdocRefer,
    ContractRefer,
    EntryTypeRefer,
    ChangeTypeRefer,
    DimiTypeRefer,
    AgeRefer,
    StaffCodeRefer,
    RangeDateRefer,
    EmptyRefer,
    FormBtn,
}
